package com.gwd.task.model;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gwd.task.entity.EventsProcessEntity;
import com.gwd.task.entity.TestProcessEntity;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @author zhiyongming
 * @date 2020/11/26 11:22
 */
@Data
public class TestProcessDTO {
    private Long tpId;
    private Long testId;
    @NotNull(message = "状态不能为空")
    private Integer testState;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private String operationTime;
    private String operationUserName;
    private Long operationUser;
    private String describe;

    public TestProcessDTO() {}
    public TestProcessDTO(EventsProcessEntity entity) {
        BeanUtil.copyProperties(entity, this);
    }

    public static TestProcessDTO LOG(Long userId, Long testId, Integer status, String describe) {
        TestProcessDTO dto = new TestProcessDTO();
        dto.setTestState(status);
        dto.setDescribe(describe);
        dto.setOperationUser(userId);
        dto.setTestId(testId);
        dto.setOperationTime(DatePattern.NORM_DATETIME_MINUTE_FORMAT.format(new Date()));

        return dto;
    }

    public TestProcessDTO(TestProcessEntity entity) {
        BeanUtil.copyProperties(entity, this, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(false));
    }
}
